	*************************************************************************
	* Inter-regional Inequality and the Dynamics of Government Spending 
	* Online Appendix -- Section 10. Social Spending Model Replication
	*************************************************************************
	*********************************************************
	** Lupu and Pontusson: Social Spending Model (Replication)
	*********************************************************
	set more 1
	set varabbrev off
	version 10
	clear all
	cd "YOUR_DIRECTORY_PATH_HERE\supplements (online appendix)\appendix p"
	use "replication_lupu_pontusson.dta", clear

	* Sort dataset
	sort id year
	tsset id year

	* Invert disproportionality measure
	replace disp_gall = -1 * disp_gall

	* Rescale variables
	replace fempar = fempar*100
	replace union = union*100

	* Standardize variables to [0,1]
	egen stdpjoint = std01(pjoint)
	egen stddisp_gall = std01(disp_gall)

	rename ADGINI adgini
	rename COVW covw
	rename COV cov

	* Interpolate missing values
	by id: ipolate ratio9050 year, gen(pratio9050)
	by id: ipolate ratio5010 year, gen(pratio5010)
	by id: ipolate ratio9050s year, gen(pratio9050s)
	by id: ipolate ratio5010s year, gen(pratio5010s)
	by id: ipolate foreign year, gen(pforeign)
	by id: ipolate voc year, gen(pvoc)
	by id: ipolate adgini year, gen(iadgini)
	by id: ipolate ineq_wpns year, gen(iineq_wpns)
	by id: ipolate ineq_spns year, gen(iineq_spns)

	* Generate immigration measure (percent foreign)
	replace pforeign = pforeign*1000
	gen fpop = (pforeign/pop)*100

	* Generate inequality measures
	gen ratio9010 = pratio9050 * pratio5010
	gen ratio9010s = pratio9050s * pratio5010s
	gen skew = pratio9050/pratio5010
	gen skews = pratio9050s/pratio5010s
	replace iadgini = iadgini*100
	replace adgini = adgini*100
	replace iineq_wpns = iineq_wpns*100
	replace iineq_spns = iineq_spns*100
	replace ineq_spns = ineq_spns*100

	* Generate five-year moving averages for social-spending models
	foreach x of varlist socspend rpop_s1_rgdppc rpop_s2_rgdp rgdppc_density adgini iadgini ineq_wpns ineq_spns iineq_wpns iineq_spns pratio9050s pratio5010s ratio9010s skews dreher pop65 stdpjoint stddisp_gall fempar unempl union turnout pvoc fpop {
		gen ma`x' = (l1.`x' + l2.`x' + l3.`x' + l4.`x' + l5.`x')/5
	}

	/*
	Country        |      Freq.     Percent        Cum.
	---------------+-----------------------------------
	Australia      |         25        7.81        7.81
	Belgium        |         14        4.38       12.19
	Canada         |         25        7.81       20.00
	Denmark        |         25        7.81       27.81
	Finland        |         23        7.19       35.00
	France         |         25        7.81       42.81
	Germany        |         16        5.00       47.81
	Ireland        |          6        1.88       49.69
	Italy          |          7        2.19       51.88
	Japan          |         25        7.81       59.69
	Netherlands    |         23        7.19       66.88
	New Zealand    |         16        5.00       71.88
	Norway         |          2        0.63       72.50
	Spain          |          4        1.25       73.75
	Sweden         |         25        7.81       81.56
	Switzerland    |          9        2.81       84.38
	USA            |         25        7.81       92.19
	United Kingdom |         25        7.81      100.00
	---------------+-----------------------------------
			 Total |        320      100.00
	*/

	*drop if country=="New Zealand"  /*Insufficient Data Points*/
	*drop if country=="Austria"      /*Insufficient Data Points*/

	*****************************************************************************************
	** Appendix P. Robust to Replication of Social Spending Model (Lupu and Pontusson, 2011)
	*****************************************************************************************
	* Model [1]
	xi: xtpcse socspend maiadgini mapratio9050s mapratio5010s gdpgrowth i.id, pairwise cor(psar1)
	predict pred if e(sample), xb
	gen resid = socspend-pred
	egen stresid=std(resid)
	gen outlier = 0 if e(sample)
	replace outlier = 1 if abs(stresid)>1.5
	
	* Model [2]
	xi: xtpcse socspend maiadgini mapratio9050s mapratio5010s gdpgrowth i.id if outlier!=1, pairwise cor(psar1)
	drop pred resid stresid outlier

	* Model [3]
	xi: xtpcse socspend maiadgini maratio9010s maskews gdpgrowth i.id, pairwise cor(psar1)
	predict pred if e(sample), xb
	gen resid = socspend-pred
	egen stresid=std(resid)
	gen outlier = 0 if e(sample)
	replace outlier = 1 if abs(stresid)>1.5
	
	* Model [4]
	xi: xtpcse socspend maiadgini maratio9010s maskews gdpgrowth i.id if outlier!=1, pairwise cor(psar1)
	drop pred resid stresid outlier

    sum socspend ratio9050 ratio5010 skew ratio9010 if country!="Austria" & country!="New Zealand"
